package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Classroom;
import cn.wolfcode.crm.query.ClassroomQueryObject;
import cn.wolfcode.crm.service.IClassroomService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("classroom")
public class ClassroomController {
    @Autowired
    private IClassroomService classroomService;

    @RequiresPermissions(value={"classroom:view","课室视图"},logical = Logical.OR)
    @RequestMapping("view")
    public String view() {
        return "classroom/classroom";
    }

    @RequiresPermissions(value={"classroom:query","课室列表"},logical = Logical.OR)
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(ClassroomQueryObject qo) {
        return classroomService.query(qo);
    }

    @RequiresPermissions(value={"classroom:selectAll","课室全选"},logical = Logical.OR)
    @RequestMapping("selectAll")
    @ResponseBody
    public List<Classroom> selectAll() {
        return classroomService.selectAll();
    }

    @RequiresPermissions(value={"classroom:saveOrUpdate","课室编辑/新增"},logical = Logical.OR)
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Classroom entity) {
        try {
            classroomService.saveOrUpdate(entity);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }
    @RequiresPermissions(value={"classroom:delete","课室删除"},logical = Logical.OR)
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        try {
            classroomService.deleteByPrimaryKey(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }

    @RequiresPermissions(value={"classroom:changState","部门状态"},logical = Logical.OR)
    @RequestMapping("changState")
    @ResponseBody
    public JsonResult changState(Long id) {
        try {
            classroomService.changState(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }



}
